'''
Created on 17.05.2010

@author: shtimn
'''
import time

from django.conf import settings
from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date
import userconfig_db as engine

class UserconfigMiddleware(object):
    def process_request(self, request):
        if request.user.is_authenticated():
            user_id = request.user.id
            request.userconfigs = engine.SessionStore(user_id)
        else:
            request.userconfigs = {}

    def process_response(self, request, response):
        """
        FIXME
        """
        try:
            modified = request.userconfigs.modified
        except AttributeError:
            pass
        else:
            if modified:
                request.userconfigs.save()
        return response
